//
//  SITitleButton.swift
//  SinaImiate
//
//  Created by xiaoming on 16/7/4.
//  Copyright © 2016年 GoodJob. All rights reserved.
//

import UIKit

class SITitleButton: UIButton {

    init(title: String?) {
        
        super.init(frame: CGRect())
        
        if title == nil {
            
            setTitle("首页", for: [])
        } else {
            
            setTitle(title! + " ", for: [])
            
            setImage(#imageLiteral(resourceName: "navigationbar_arrow_down"), for: [])
            setImage(#imageLiteral(resourceName: "navigationbar_arrow_up"), for: .selected)
        }
        
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        setTitleColor(UIColor.darkGray(), for: [])
        
        sizeToFit()
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        guard let titleLabel = titleLabel, imageView = imageView else {
            
            return
        }
        
//        titleLabel.frame = titleLabel.frame.offsetBy(dx: -imageView.bounds.width, dy: 0)
//        imageView.frame = imageView.frame.offsetBy(dx: titleLabel.bounds.width, dy: 0)
    
        titleLabel.frame.origin.x = 0
        imageView.frame.origin.x = titleLabel.bounds.width
    }

}
